<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.org/ui"
      xmlns:c="http://java.sun.com/jsp/jstl/core">

    <ui:composition template="/template.xhtml">
        <ui:define name="title">
            <h:outputText value="Meu Carrinho"></h:outputText>
        </ui:define>
        <ui:define name="body">
            <h:form styleClass="jsfcrud_list_form" id="form">


                <p:panel>

                    <p:growl id="growl" showDetail="true"/> 

                    <p:panelGrid columns="4"  style=" width: 1400px; tab-size: 12" id="view">

                        <f:facet name="header">
                            <h3>Meu Carrinho</h3>
                        </f:facet> 

                        <h:outputText value="#{bundle.ViewClientLabel_name}"  />
                        <h:outputText value="#{orderesController.carrinhoCompra.client.name}" title="#{bundle.ViewClientTitle_name}"/>
                        <h:outputText value="#{bundle.ViewAddressLabel_street}"/>
                        <h:outputText value="#{orderesController.carrinhoCompra.client.address.street}" title="#{bundle.ViewClientTitle_address}"/>
                        <h:outputText value="#{bundle.ViewAddressLabel_city}"/>
                        <h:outputText value="#{orderesController.carrinhoCompra.client.address.city}" title="#{bundle.ViewAddressTitle_city}"/>
                        <h:outputText value="#{bundle.ViewAddressLabel_stateORprovince}"/>
                        <h:outputText value="#{orderesController.carrinhoCompra.client.address.stateORprovince}" title="#{bundle.ViewAddressTitle_stateORprovince}"/>
                        <h:outputText value="#{bundle.ViewAddressLabel_postalCode}"/>
                        <h:outputText value="#{orderesController.carrinhoCompra.client.address.postalCode}" title="#{bundle.ViewAddressTitle_postalCode}"/>
                        <h:outputText value="#{bundle.ViewAddressLabel_contry}"/>
                        <h:outputText value="#{orderesController.carrinhoCompra.client.address.contry}" title="#{bundle.ViewAddressTitle_contry}"/>


                        <f:facet name="footer">


                            <h:panelGroup> 


                                <p:dataTable id="product" value="#{orderesController.carrinhoItensLista}" editable="true" widgetVar="pro" editMode="cell" var="item" style="border:solid 1px">


                                    <f:facet name="footer">
                                        <h:outputText value="Via WebApplication" /> 
                                    </f:facet>

                                    <p:column headerText="Excluir">
                                        <p:commandButton value="Excluir"   action="#{orderesController.deleteProductOnCarrinho(item.product.ID)}" update="product" />
                                        
                                        
                                    </p:column>
                                        

                                    <p:column>
                                        <f:facet name="header">
                                            <h:outputText value="ID"/>
                                        </f:facet>
                                        <h:outputText value="#{item.product.ID}"/>
                                    </p:column>

                                    <p:column>
                                        <f:facet name="header">
                                            <h:outputText value="Descricao"/>
                                        </f:facet>
                                        <h:outputText value="#{item.product.description}"/>    
                                    </p:column>


                                    <p:column>
                                        <f:facet name="header">
                                            <h:outputText value="Preço Unitario"/>
                                        </f:facet>
                                        <h:outputText value="$ #{item.product.price}0"/>
                                    </p:column>
                                    <p:column headerText="QTD">

                                        <p:cellEditor>  
                                            <f:facet name="output"><h:outputText value="#{item.quanttity}" /></f:facet>  
                                            <f:facet name="input">
                                                <p:inputText value="#{item.quanttity}" style="width:96%" >
                                                    <p:ajax  update="product" />
                                                </p:inputText>   
                                            </f:facet>  
                                        </p:cellEditor>  

                                    </p:column>
                                    <p:column width="400">
                                        <f:facet name="header">
                                            <h:outputText value="Valor"/>
                                        </f:facet>
                                        <h:outputText value=" $ #{item.product.price * item.quanttity}"/>
                                    </p:column>

                                    <p:columnGroup type="footer">  
                                        <p:row>  
                                            <p:column colspan="5" footerText="Valor Total:"  
                                                      style="text-align:right"  />  
                                            <p:column footerText="$ #{orderesController.CarvalorTotal()}" />  
                                        </p:row>  
                                    </p:columnGroup>  

                                    
                                </p:dataTable>
                                <p:commandButton label="Enviar Pedido" value="Enviar Pedido" action="#{orderesController.enviarPedido()}" />
                            </h:panelGroup>
                        </f:facet>
                        
                    </p:panelGrid>

                </p:panel>
                <br />

            </h:form>
        </ui:define>
    </ui:composition>

</html>
